package com.testplatform.aitestplatform.utils;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

public class OnlinePdfReader {
    
    public static String readPdfFromUrl(String pdfUrl) {
        try (InputStream inputStream = new URL(pdfUrl).openStream();
             PDDocument document = PDDocument.load(inputStream)) {
            
            PDFTextStripper textStripper = new PDFTextStripper();
            return textStripper.getText(document);
            
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

}